package com.aries.client.consts;

import com.aries.commons.domains.ServerResponseWrapper;

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.*;

public class ThreadPool {

    /**
     * 每5分钟清理一下response map，防止oom
     */
    static {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        scheduledExecutorService.schedule(() -> {

            Map<String, ServerResponseWrapper> map = ChannelConst.RESPONSE_MAP;
            Iterator<java.util.Map.Entry<String, ServerResponseWrapper>> iterable = map.entrySet().iterator();
            if (iterable.hasNext()) {
                java.util.Map.Entry<String, ServerResponseWrapper> entry = iterable.next();
                if (entry.getValue().getGot()) {
                    iterable.remove();
                }
            }

        }, 5L, TimeUnit.MINUTES);
    }

}
